<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="saxbean.*" %>
<%@ page import="org.xml.sax.*" %>

<jsp:useBean id="saxparser" 
class="saxbean.MySAXParserBean" />

<%
Collection stocks = saxparser.parse("/opt/apache-tomcat-6.0.26/webapps/Spatialytics/WEB-INF/aguram.xml");

Vector vect = (Vector)stocks;
Iterator ir = stocks.iterator();
int st = 0;
boolean first = true;
String t_gm = "";
String dime = "{";

dime += "\"Cubes\": [";
%>

<%
for(int y=0;y<vect.size();y++){
  MyElement element = (MyElement) vect.get(y); 
  String tag = element.getQname();
  String name = element.getAttributesI().getValue("name");

  
if(tag.equals("Cube")){

if(!first){
	dime = dime.substring(0,dime.length()-1);
	dime += "]},";
}
first = false;
	dime += "{ \"name\":\""+name+"\",";
	dime += "\"Dimensions\" : [";

  }
%>

<%
	

	if(tag.equals("Dimension")){
	String curr_dim="{\"name\":\""+name+"\",\"Hierarchies\":[";
	
	for(int p=1;p<vect.size()-y;p++)
	{
		MyElement elt = (MyElement) vect.get(y+p); 

		if("Dimension".equals(elt.getQname())){break;}
		else if("Hierarchy".equals(elt.getQname())){
		String allmn = elt.getAttributesI().getValue("allMemberName");
		String t_name = elt.getAttributesI().getValue("name");
		curr_dim+="{\"allmn\":\""+allmn+"\",\"name\":\"";
		curr_dim+=t_name;
		curr_dim+="\"},";
		}
		else if("Property".equals(elt.getQname())){
			
			if("Geometry".equals(elt.getAttributesI().getValue("type"))){t_gm+=(t_gm.equals(""))?st:"";}
				
		}
	}
	
	curr_dim = curr_dim.substring(0,curr_dim.length()-1);
	curr_dim+="]";
	dime+=curr_dim;
	dime+="},";
	st++;
	
	
}  %>
  <% }
	dime = dime.substring(0,dime.length()-1);
	dime +="]}]";
	dime+=",\"geom\":\""+t_gm+"\"";
	
	//dime+="\"user\" : " + file_content;
	dime+="}";
  %>
 
<%= dime %>

